<?PHP
include "../../../mainfile.php";


//ADD NEW CITY CODE
if($_POST['action'] == 'add_city'){
		$xoopsDB->query("INSERT INTO " . $xoopsDB->prefix('weather') . " values ('0','".trim($_POST['name'])."','".trim($_POST['code'])."','false')");
	    redirect_header('index.php?op=codes&amp;currentID=0', 1, 'You have succesfully added the following city: '.mysql_real_escape_string($_POST['name']));
}


//EDIT Subject Line / Recipient Pair 
if($_POST['action'] == 'edit_city'){ 
		$name = ereg_replace("[^A-Za-z0-9, ' ']", "", $_POST['name']);
		$code = ereg_replace("[^A-Za-z0-9, ' ']", "", $_POST['code']); 
		$xoopsDB->query("UPDATE " . $xoopsDB->prefix('weather') . " SET name = '".mysql_real_escape_string($name)."', code = '".$code."' WHERE ID = '".$_POST['ID']."'");
	    redirect_header('index.php?op=codes&amp;currentID=0', 1, 'You have succesfully updated '.$name.'!');
}


//DELETE Subject Line / Recipient Pair
if($_POST['action'] == 'delete_city'){
	$xoopsDB->query("DELETE FROM ".$xoopsDB->prefix("weather")." WHERE ID=".$_POST['ID']."");
    redirect_header('index.php?op=codes&currentID=0', 1, 'You have succesfully deleted '.$_POST['name'].'!');
}

//MAKE DEFAULT CITY
if($_POST['action'] == 'make_default'){
		$xoopsDB->query("UPDATE " . $xoopsDB->prefix('weather') . " SET `default` = 'false' WHERE `default` = 'true'");
		$xoopsDB->query("UPDATE " . $xoopsDB->prefix('weather') . " SET `default` = 'true' WHERE ID = ".$_POST['ID']." LIMIT 1");
    	/* foreach (glob(XOOPS_ROOT_PATH."/cache/*") as $filename) {
			if($filename!='adminmenu.php'){
			unlink($filename);
			}
		} */
		redirect_header('index.php?op=codes&currentID=0', 1, 'You have succesfully made '.$_POST['name'].' the default city!');
}
?>